<template>
  <div class="signIn">
    <van-nav-bar
      title="登录"
      left-text="返回"
      left-arrow
      @click-left="onClickLeft"
      fixed
      placeholder
    />
    <div class="kuang"></div>
    <!-- 输入手机号，调起手机号键盘 -->
    <van-field v-model="tel" type="tel" label="手机号" />
    <!-- 输入密码 -->
    <van-field
      v-model="password"
      :type="wenben"
      label="密码"
      :right-icon="img"
      @click-right-icon="qiehuan"
    />
    <div class="login-btn">
      <van-button round block color="#0C34BA" @click="dianji">登录</van-button>
    </div>
    <div class="login-btn">
      <van-button round block @click="register">注册</van-button>
    </div>
  </div>
</template>

<script>
import { Toast } from "vant";
export default {
  name: "SignIn",
  data() {
    return {
      tel: "",
      password: "",
      wenben: "password",
      img: "closed-eye",
    };
  },
  created() {},
  methods: {
    onClickLeft() {
      Toast("返回");
      this.$router.go(-1);
    },
    register() {
      this.$router.push({ name: "Register" });
    },
    dianji() {
      // 获取cookie
      var cookieData = document.cookie;
      var cookies = cookieData.split("; ");
      var cookieObject = {};
      for (var i = 0; i < cookies.length; i++) {
        var c = cookies[i].split("=");
        cookieObject[c[0]] = c[1];
      }
      // console.log("cookieObject ==> ", cookieObject);
      //获取账号密码
      var text = cookieObject.text;
      var tel = cookieObject.tel;
      var password = cookieObject.password;
      // console.log("text ==> ", text);
      // console.log("tel ==> ", tel);
      // console.log("password ==> ", password);
      if (this.tel == "") {
        Toast("请输入手机号");
      } else if (this.password == "") {
        Toast("请输入密码");
      } else {
        if (this.tel !== tel) {
          Toast("手机号不正确");
          return;
        } else {
          // console.log("手机号正确");
        }
        if (this.password !== password) {
          Toast("密码不正确");
          return;
        } else {
          // console.log("密码正确");
          Toast("登陆成功");
          this.$router.push({ name: "home" });
        }
      }
    },
    qiehuan() {
      if (this.wenben == "password") {
        this.wenben = "text";
        this.img = "eye-o";
      } else {
        this.wenben = "password";
        this.img = "closed-eye";
      }
    },
  },
};
</script>
<style lang="less" scoped>
.login-btn {
  margin-top: 15px;
}
.kuang {
  width: 100%;
  height: 200px;
}
</style>